package com.eol.admin.modules.business.member;

import com.eol.admin.modules.logging.log.Log;
import com.eol.common.constants.BaseCommonConstants;
import com.eol.entity.po.member.ZMember;
import com.eol.mapper.config.tkMybatis.TableData;
import com.eol.service.member.ZMemberService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 2020/6/2
 * Time: 12:17 PM
 * Description: MemberController
 */
@RestController
@RequestMapping("api/member")
public class MemberController {

    @Resource
    private ZMemberService zMemberService;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ResponseEntity<Object> list(@RequestParam(value = "page", defaultValue = BaseCommonConstants.PAGE_HELP_PAGE) Integer page,
                                       @RequestParam(value = "size", defaultValue = BaseCommonConstants.PAGE_HELP_LIMIT) Integer limit,
                                       @RequestParam(value = "phone", required = false) String phone) {
        PageHelper.startPage(page + 1, limit);
        List<ZMember> list = zMemberService.selectByAdmin(ZMember.builder()
                .phone(phone)
                .build());
        PageInfo<ZMember> pageInfo = new PageInfo<>(list);
        TableData<ZMember> tableData = new TableData<>(pageInfo.getTotal(), list);
        PageHelper.clearPage();
        return new ResponseEntity<>(tableData, HttpStatus.OK);
    }
}
